#include<bits/stdc++.h>
using namespace std;

int w;
long long n;

int main()
{
	cin >> w;
	cin >> n;
	int res = (w + n%7)%7;
	if(res != 0)
		cout << res << endl;
	else
		cout << 7 << endl;
	
	
	return 0;
 } 